package com.hmdp.config;

import com.hmdp.core.service.impl.RedisServiceImpl;
import com.hmdp.interceptors.LoginInterceptor;
import com.hmdp.interceptors.RFlashTokenInterceptor;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
import org.springframework.web.servlet.config.annotation.ResourceHandlerRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;

import javax.annotation.Resource;

/**
 * @author 计算机系 ITAEM 摆渡人
 * @description
 * @date 2022/10/15 20:52
 */
@Configuration
public class WebMvcConfig implements WebMvcConfigurer {

    @Resource
    private RedisServiceImpl redisService;

    @Override
    public void addInterceptors(InterceptorRegistry registry) {
        //token刷新拦截器
        registry.addInterceptor(new RFlashTokenInterceptor(redisService))
                .addPathPatterns("/**")
                .order(0);
        //登录拦截器
        registry.addInterceptor(new LoginInterceptor())
                .excludePathPatterns(
                        "/user/code",
                        "/user/login",
                        "/blog/hot",
                        "/shop/**",
                        "/shop-type/**",
                        "/upload/**",
                        "/voucher/**",
                        "/v3/api-docs",
                        "/favicon.ico"
                )
                .order(1);
    }
}
